<?php
/**
 * Created by PhpStorm.
 * User: yxs
 * Date: 2017/6/5
 * Time: 17:20
 */

namespace model;

use library\common\str;
use think\Model;

class ShopOrderItem extends BaseModel
{
    protected $insert = ['order_sn', 'order_time'];

    public function shopStore()
    {
        return $this->belongsTo('ShopStore', "store_id")->field('id,name,logo,mobile,flag_lock,bizhours_start,bizhours_end');
    }

    public function getOrderTimeAttr($value)
    {
        return date("Y-m-d H:i:s", $value);
    }

    public function shopOrderGoods()
    {
        return $this->hasMany('ShopOrderGoods', "order_item_id");
    }

    public function setOrderTimeAttr()
    {
        return time();
    }

    public function getFlagStatusAttr($value)
    {
        $text = ["未配送", "正在配送", "申请取消", "确定取消", "取消订单", "货到付款(未配送)", "正在配送(货到付款)","已收货"];
        return ["value" => $value, "text" => $text[$value]];
    }

    public function setOrderSnAttr()
    {
        return str::orderNo();
    }
}